

<!-- 系统设置 -->
<template>
	<view class="container">
		<view class="oneRow">
			<view class="list-cell b-b radiusT10" @click="navTo('/pagesUser/login/bindPhone')" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">更换手机</text>
				<text class="cell-tip" v-if="phoneOne">{{phoneOne+'****'+phoneTwo}}</text>
				<text class="cell-tip" v-if="!phoneOne">未绑定</text>
				<text class="cell-more yticon icon-you"></text>
			</view>
			<!-- <view class="list-cell radiusB10"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">语言选择</text>
				<text class="cell-tip unSet" v-if="wx == '10'" @click="bindWxHandler()">中文</text>
				<text class="cell-tip unSet" v-if="wx == '20'" @click="bindedTipsHandler()">已绑定</text>
				<text class="cell-more yticon icon-you"></text>
			</view> -->
			<!-- <view class="list-cell radiusB10"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">绑定微信</text>
				<text class="cell-tip unSet" v-if="wx == '10'" @click="bindWxHandler()" style="color: #D21728;">未绑定</text>
				<text class="cell-tip unSet" v-if="wx == '20'" @click="bindedTipsHandler()">已绑定</text>
				<text class="cell-more yticon icon-you"></text>
			</view> -->
		</view>


		<view class="oneRow">
			<view class="list-cell b-b radiusB10" @click="navTo('payPass')" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">资金密码</text>
				<text class="cell-tip unSet" v-if="!payword">未设置</text>
				<text class="cell-tip unSet" v-if="payword">修改</text>
				<text class="cell-more yticon icon-you"></text>
			</view>
			<view class="list-cell b-b radiusT10" @click="navTo('/pagesUser/bankCard/myCard')" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">收款方式</text>
				<text class="cell-tip unSet" v-if="!password">未设置</text>
				<text class="cell-tip unSet" v-if="password">修改</text>
				<text class="cell-more yticon icon-you"></text>
			</view>
			<view class="list-cell b-b radiusT10" @click="navTo('/pagesUser/login/resetPass')" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">登录密码</text>
				<text class="cell-tip unSet" v-if="!password">未设置</text>
				<text class="cell-tip unSet" v-if="password">修改</text>
				<text class="cell-more yticon icon-you"></text>
			</view>
		</view>

		<view class="oneRow">
			<view class="list-cell b-b radiusT10" @click="toRichtext('1')" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">用户协议</text>
				<text class="cell-more yticon icon-you"></text>
			</view>
			<view class="list-cell b-b radiusB10" @click="toRichtext('2')" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">隐私政策</text>
				<text class="cell-more yticon icon-you"></text>
			</view>
			<!-- -#ifdef APP-PLUS -->
			<view class="list-cell radiusB10" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">当前版本</text>
				<text class="cell-tip">V{{versionCode}}</text>
			</view>
			<!-- -#endif -->
		</view>

		<!-- 退出登录 -->
		<view class="oneRow">
			<view class="list-cell log-out-btn" @click="toLogout">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
  
	export default {
		data() {
			return {
				icon: {
					backBtn: "/static/images/common/return.png"
				},
				password: false,
				payword: false,
				wx: false,
				telephone: '',
				phoneOne: '',
				phoneTwo: '',

				//当前版本号
				versionCode: '1.0.6'
			};
		},
		onShow() {
			let that = this;
			that.$api.globalUtil.getUserInfo(that, function(res) {
				that.wx = res.data.response.boundWx;
				that.password = res.data.response.boundPwd;
				that.payword = res.data.response.boundPayPwd;
				that.telephone = res.data.response.telephone;
				that.phoneOne = res.data.response.telephone[0] + res.data.response.telephone[1] + res.data.response.telephone[2];
				that.phoneTwo = res.data.response.telephone[7] + res.data.response.telephone[8] + res.data.response.telephone[9] +
					res.data.response.telephone[10];
			});
			
			
			// #ifdef APP-PLUS
			if (plus.os.name.toLowerCase() === 'android') {
				that.versionCode = "2.0.0";
			}else{
				that.versionCode = "2.0.0";
			}
			// #endif
		},
		methods: {
			...mapMutations(['logout']),

			navTo(url) {
				if (url == 'payPass') {
					if (!this.phoneOne) {
						this.$api.msg('请先绑定手机号');
						return;
					}
				}
				uni.navigateTo({
					url: url + '?phone=' + this.telephone + '&title=收款方式'
				});
			},
			
			
			//绑定微信操作
			bindWxHandler() {
				
				var that = this;
				uni.login({
					provider: 'weixin',
					success: function (authRes) {
						
						console.log("登录信息 = "+JSON.stringify(authRes));
						
						// 获取用户信息
						uni.getUserInfo({
							provider: 'weixin',
							withCredentials: true,
							success: function (infoRes) {
								console.log("用户信息"+JSON.stringify(infoRes));
								console.log({ 
									nickName: infoRes.userInfo.nickName,
									headImg: infoRes.userInfo.avatarUrl,
									openId: infoRes.userInfo.openId,
									unionId: infoRes.userInfo.unionId
								});
								
								that.$api.globalUtil.requestAjax({
									url: "/wechatCustomer/wechatUnion",
									method: "POST",
									data: {
										openId: infoRes.userInfo.openId,
										unionId: infoRes.userInfo.unionId
									},
									success: function(res) {
										if(res.data.success) {
											that.$api.msg("绑定成功");
											
											
											// 用户信息
											that.$api.globalUtil.getUserInfo(that, function(res) {
												console.log("----"+res.data.response.boundWx);
												that.wx = res.data.response.boundWx;
												that.password = res.data.response.boundPwd;
												that.payword = res.data.response.boundPayPwd;
												that.telephone = res.data.response.telephone;
												that.phoneOne = res.data.response.telephone[0] + res.data.response.telephone[1] + res.data.response.telephone[2];
												that.phoneTwo = res.data.response.telephone[7] + res.data.response.telephone[8] + res.data.response.telephone[9] +
													res.data.response.telephone[10];
											});
										}else {
											that.$api.msg(res.data.msg || "绑定失败");
											uni.hideLoading();
										}
									}
								});
							},
							fail(err) {
								that.$api.msg("绑定失败");
								uni.hideLoading();
							}
						});
					},
					fail(err) {
						that.$api.msg("绑定失败");
						uni.hideLoading();
					}
				});
			},
			
			
			//提示已绑定
			bindedTipsHandler() {
				this.$api.msg("您已绑定微信");
			},
			
			
			//退出登录
			toLogout() {
				var that = this;
				uni.showModal({
					content: '确定要退出登录么',
					success: (e) => {
						if (e.confirm) {
							that.logout();
							uni.removeStorageSync('addressData');
							uni.removeStorageSync('shopCartData');
							uni.removeStorageSync("orderStatus");
							uni.removeStorageSync('wxInfo');
							uni.removeStorageSync("tokenInfo");
							
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/index/index'
								})
							}, 1500)
						}
					}
				});
			},
			switchChange(e) {
				let statusTip = e.detail.value ? '打开' : '关闭';
				this.$api.msg(`${statusTip}消息推送`);
			},
			toRichtext(type) {
				uni.navigateTo({
					url: '/pagesUser/userRichtext?type=' + type
				});
			}
		}
	}
</script>

<style lang='scss'>
	page {
		background: #F5F5F5;
	}

	// header部分
	.header-Container {
		position: relative;
		width: 100%;
		height: 176rpx;
		overflow: hidden;
		box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.08);
		background: rgba(255, 255, 255, 1);

		.leftBtns {
			display: flex;
			align-items: center;
			justify-content: flex-start;
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;

			.back {
				margin-left: 17rpx;
				width: 44rpx;
				height: 44rpx;
			}
		}

		.title {
			position: absolute;
			bottom: 0;
			width: 100%;
			height: 86rpx;
			line-height: 86rpx;
			text-align: center;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: rgba(51, 51, 51, 1);
		}
	}

	.container {
		.oneRow {
			margin-top: 20rpx;
			padding: 0 30rpx;
			border-radius: 10rpx;

			.radiusT10 {
				border-radius: 10rpx 10rpx 0 0;
			}

			.radiusB10 {
				border-radius: 0 0 10rpx 10rpx;
			}
		}
	}

	.list-cell {
		display: flex;
		align-items:center;
		padding: 0 30rpx 0 45rpx;
		height: 106rpx;
		line-height: 106rpx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 170rpx;
			margin-bottom: 40rpx;
			padding: 0;
			width: 690rpx;
			height: 100rpx;
			line-height: 100rpx;
			background: rgba(255, 255, 255, 1);
			border-radius: 10rpx;
			text-align: center;
			font-size: 34rpx;
			font-family: PingFang;
			/* font-weight:500; */
			color: #FE5E49;
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30rpx;
			right: 30rpx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: $font-lg;
			color: $font-color-light;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			margin-right: 10upx;
			font-size: 28rpx;
			font-family: PingFang;
			color: rgba(51, 51, 51, 1);
		}

		.cell-tip {
			font-size: 28rpx;
			font-family: PingFang;
			/* font-weight:500; */
			color: rgba(102, 102, 102, 1);
			line-height: 55rpx;

			&.unBind {
				color: #D21728;
			}

			&.unSet {
				color: #999999;
			}
		}
	}
</style>
